<template>
	<view class="content">
		<view class="cu-list menu-avatar solid-top">
			<view class="cu-item " v-for="item in list" :key="item.name">
				<view class="cu-avatar round lg">
					<image class="response round" style="height: 100%;" :src="'../../static/photo/'+item.photo" mode="aspectFill"></image>
				</view>
				<view class="content">
					<view class="text-pink">
						<view class="text-cut">{{item.name}}{{item.phone}}</view>
					</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">{{item.time}}</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-xs">收益</view>
					<view class="cu-tag round bg-red sm">{{item.integral}}</view>
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				loadingType: 'more',
				page: 1,
				limit: 10,
				list: []
			}
		},
		onLoad() {
			this.getList();
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = "fixed";
			} else {
				this.headerPosition = "absolute";
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.loadData('refresh');
		},
		//加载更多
		onReachBottom() {
			this.loadData("add");
		},
		methods: {

			//加载商品 ，带下拉刷新和上滑加载
			loadData(type) {
				//没有更多直接返回

				if (type === 'add') {
					if (this.loadingType === 'nomore') {
						return;
					}
					this.loadingType = 'loading';
				} else {
					this.loadingType = 'more'
				}
				var that = this;
				that.page = that.page + 1;

				if (type === 'refresh') {
					this.list = [];
					this.page = 1;
				}

				if (type === 'refresh') {
					uni.stopPullDownRefresh();
				}
				that.getList();
			},
			getList() {
				if (this.loadingType == 'nomore') {
					return;
				}
				var that = this;
				that.$network.request("UserAction/myFriend", {
					page: that.page,
					limit: that.limit
				}, function(res) {
					let list = that.list;
					console.log(list)
					
					that.list = list.concat(res.data.list);
					if (res.data.list == 0 || that.list.length < that.limit) {
						that.loadingType = 'nomore';
						return;
					}
				}, "", function(res) {
					console.error(JSON.stringify(res))
					uni.showToast({
						icon: 'none',
						title: '加载失败',
						duration: 1200
					})
				});
			}
		}
	}
</script>

<style>

</style>
